﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.IO;
using Newtonsoft.Json;

namespace ClassLibrary1
{
    public class HttpUtil
    {
        public static string Get(string url)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Proxy = null;
            request.KeepAlive = false;
            request.Method = "GET";
            request.ContentType = "application/json; charset=UTF-8";
            request.AutomaticDecompression = DecompressionMethods.GZip;

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream myResponseStream = response.GetResponseStream();
            StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.UTF8);
            string retString = myStreamReader.ReadToEnd();

            myStreamReader.Close();
            myResponseStream.Close();

            if (response != null)
            {
                response.Close();
            }
            if (request != null)
            {
                request.Abort();
            }

            return retString;
        }

        public static List<ItemInfo> GetPhotoAlbums(String url)
        {
            string jsonStr = Get(url);
            return JsonConvert.DeserializeObject<List<ItemInfo>>(jsonStr);
        }

    }


    public class ItemInfo
    {

        public string albumId { get; set; }
        public bool canDelete { get; set; }
        public bool canDeleteBucket { get; set; }
        public bool canImport { get; set; }
        public int count { get; set; }
        public string name { get; set; }
        public string parentNode { get; set; }
        public string thumbnailUrl { get; set; }
    }

    public class PhotoAlbums
    {
        public List<ItemInfo> Items;
    }
}
